<%@page import="java.text.SimpleDateFormat"%>
<%@page import="comment.CommentVo"%>
<%@page import="common.SerialDAO"%>
<%@page import="common.SerialDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="comment.CommentMyBa"%>
<%@page import="Board.BoardVo"%>
<%@page import="Board.BoardMyba"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
#repl_cont {
	width: 700px;
	height: 135px;
	background-color: #f8f6fd;
	padding-bottom: 10px;
}

#co_modi_btns {
	margin-top: 10px;
	margin-right: 40px;
	float: right;
}

#coModiBtn {
	width: 45px;
	height: 23px;
	color: #ffffff;
	/* font-weight: bold; */
	background-color: #111111;
	border: none;
	padding: 3px 5px;
	cursor: pointer;
	font-size: 12px;
}

#coDelBtn {
	width: 45px;
	height: 23px;
	color: #ffffff;
	/* font-weight: bold; */
	background-color: #111111;
	border: none;
	padding: 3px 5px;
	cursor: pointer;
	font-size: 12px;
}

#texAre {
	margin-top: 10px;
}

/* ------------  */
#repl_list {
	width: 700px;
	margin-top: 20px;
}

#repl_solid_line {
	width: 700px;
	clear: both;
	border-top: 1px solid #dddddd;
}

#repl_writer,#repl_content {
	display: inline-block;
	vertical-align: middle;
}

#repl_write {
	font-size: 12px;
	padding-top: 3px 0 3px 0;
}

#repl_writer,#repl_writer1 {
	width: 94px;
	float: left;
	padding: 3px;
	font-size: 12px;
	color: #333333;
	font-weight: bold;
	text-align: center;
}

#repl_content {
	width: 594px;
	height: auto;
	padding: 3px;
	float: left;
	font-size: 12px;
	font-weight: bold;
	text-align: center;
}

#repl_content1 {
	width: 467px;
	padding: 3px 3px 3px 30px;
	float: left;
	font-size: 12px;
	color: #777777;
	white-space: nowrap; /* ㅡㅡㅡㅡㅡㅡㅡㅡㅡ텍스트 넘치지 않게ㅡㅡㅡㅡㅡㅡㅡㅡ  */
	overflow: hidden;
	text-overflow: ellipsis;
	/* background-color: #ff00ff; */
	text-decoration: underline;
	cursor: pointer;
}

#repl_content1:hover {
	color: #000000;
}

#repl_date1 {
	width: 98px;
	float: left;
	/* background-color: #333333; */
}
</style>
<script>
	function btnToggle(i) {
		var item2 = document.getElementsByName("item2");

		//토글처리..
		if (item2[i].style.display == 'none') {
			item2[i].style.display = '';
		} else {
			item2[i].style.display = 'none';
		}

	}

	function comodi(i) {
		var dddd = document.getElementsByName('bbaa');
		var cccc = document.getElementsByName('ccdd');
		var eeee = document.getElementsByName('eeff');

		var params = "BO_no=" + dddd[i].value;
		params = params + "&CO_content=" + eeee[i].value;
		params = params + "&CO_no=" + cccc[i].value;

		$
				.ajax({
					url : '${pageContext.request.contextPath}/homepage/board/comment_modify.jsp',
					type : 'POST',
					cache : false,
					data : params,
					success : function(html) {
						init();
					}
				});

	}

	function codel(i) {

		var dddd = document.getElementsByName('bbaa');
		var cccc = document.getElementsByName('ccdd');
		var eeee = document.getElementsByName('eeff');

		var params = "BO_no=" + dddd[i].value;
		params = params + "&CO_content=" + eeee[i].value;
		params = params + "&CO_no=" + cccc[i].value;

		/* alert(i); */
		$
				.ajax({
					url : '${pageContext.request.contextPath}/homepage/board/comment_delete.jsp',
					type : 'POST',
					cache : false,
					data : params,
					success : function(html) {
						
						init();
						alert("해당 댓글이 삭제되었습니다!");
					}
				});
	}
</script>


</head>
<body>
	<jsp:useBean id="commentVo" class="comment.CommentVo"></jsp:useBean>
	<jsp:setProperty property="*" name="commentVo" />
	<%
		CommentMyBa comment = new CommentMyBa();

	if((commentVo.getCO_content()) != null && !(commentVo.getCO_content()).equals("")){
		comment.setCommentVo(commentVo);
		int cnt = comment.insert();	
	}
	%>



	<%
		String no = request.getParameter("BO_no");
	comment = new CommentMyBa();
	comment.setBO_no(no);
	comment.setSA_nm((String)session.getAttribute("SA_nm"));  //사원이름 코멘트 테이블에 추가 해서 세션에 있는걸 넣어줌
	ArrayList<CommentVo> list = comment.list();


	String SA_no = (String)session.getAttribute("SA_no");
	/* out.print(comment.getSA_nm()); */
	String Mid = (String)session.getAttribute("Mid");
	%>

	<%
		for(int i=0; i<list.size();i++){
			CommentVo vo = list.get(i);

		if(i==0){
	%>

	<h5>*회원님들께서 남기신 댓글입니다.</h5>
	<div id="repl_list">
		<div id="repl_solid_line"></div>
		<div id="repl_writer">이름</div>
		<div id="repl_content">내용</div>
		<div id="repl_solid_line"></div>
		<%
			}
		%>


		<div id="repl_write" name="item1" style="clear: both;">
			<div id="repl_writer1"><%=vo.getSA_nm()%></div>
			<div align="left" name="item_content">
				<span id="repl_content1" onclick="btnToggle('<%=i%>')"><%=vo.getCO_content()%></span>
			</div>
			<div id="repl_date1"><%=vo.getRG_dt().substring(0, 11).replace("-", "/")%></div>
			<!-- 서브스트링 주는방법.. 리플레이스하는 방법..  -->
		</div>
		<!-- <div id="comment_result">
	
	</div> -->
		<div id="repl_cont" style="display: none;" name="item2">

			<%
				if(Mid.equals(vo.getSA_no())) {
			%>
			<form name="text_frm" method="post" action="">
				<textarea rows="4" cols="80" style="resize: none;" name="eeff"
					id="texAre"><%=vo.getCO_content()%></textarea>
				<br />
				<div id="co_modi_btns">
					<input type="button" value="수정" name="coModi"
						onclick="comodi('<%=i%>')" id="coModiBtn"> <input
						type="button" value="삭제" name="coDele" onclick="codel('<%=i%>')"
						id="coDelBtn">
				</div>

				<input type="hidden" value="<%=vo.getBO_no()%>" id="bbaa"
					name="bbaa">
				<!-- <%=vo.getBO_no()%>  -->
				<input type="hidden" value="<%=vo.getCO_no()%>" id="ccdd"
					name="ccdd">
				<!-- <%=vo.getCO_no()%>  -->
				<input type="hidden" value="<%=vo.getSA_no()%>" name="SA_no">
				<input type="hidden" value="<%=vo.getSA_nm()%>" name="SA_nm">
			</form>
			<%
				}else{
			%>
			<textarea rows="4" cols="80" style="resize: none;" name="eeff"
				readonly id="texAre"><%=vo.getCO_content()%></textarea>
			<br /> <input type="hidden" value="수정" name="coModi"
				onclick="comodi('<%=i%>')"> <input type="hidden" value="삭제"
				name="coDele" onclick="codel('<%=i%>')"> <input
				type="hidden" value="<%=vo.getBO_no()%>" id="bbaa" name="bbaa">
			<!-- <%=vo.getBO_no()%>  -->
			<input type="hidden" value="<%=vo.getCO_no()%>" id="ccdd" name="ccdd">
			<!-- <%=vo.getCO_no()%>  -->
			<%
				}
			%>
		</div>
		<%
			}
		%>
		<div style="height: 20px;"></div>
	</div>
	<div style="height: 20px;"></div>

</body>
</html>